﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WineDAL
{
    public class Consignees_ShowDAL
    {
        SQLHelper helper = new SQLHelper();
        /// <summary>
        /// 显示用户收货地址
        /// </summary>
        /// <param name="UsersID"></param>
        /// <returns></returns>
        public ArrayList Consignees_Show(int UsersID)
        {
            SqlParameter par = new SqlParameter("@UsersID", UsersID);
            DataTable table = helper.ExecDataTable_Proc("Consignee_Show", par);
            //JavaScriptSerializer jss = new JavaScriptSerializer();
            System.Collections.ArrayList dic = new System.Collections.ArrayList();
            foreach (DataRow dr in table.Rows)
            {
                System.Collections.Generic.Dictionary<string, object> drow = new System.Collections.Generic.Dictionary<string, object>();
                foreach (DataColumn dc in table.Columns)
                {
                    drow.Add(dc.ColumnName, dr[dc.ColumnName]);
                }
                dic.Add(drow);
            }
            return dic;
        }
        /// <summary>
        /// 删除用户收货地址
        /// </summary>
        /// <param name="ConsigneeID"></param>
        /// <returns></returns>
        public int Consignees_Del(int ConsigneeID)
        {
            SqlParameter[] pare = new SqlParameter[]{
            new SqlParameter("@id",ConsigneeID)
           };
            return helper.ExecNonquery_Proc("DelAddConsignee", pare);
        }
        /// <summary>
        /// 添加用户收货地址
        /// </summary>
        /// <param name="Consignee"></param>
        /// <returns></returns>
        public int Consignees_Add(WineModel.Consignee Consignee)
        {
            SqlParameter[] par ={
                               new SqlParameter("@ConsigneeName",Consignee.ConsigneeName),
                               new SqlParameter("@AreaID",Consignee.AreaID),
                               new SqlParameter("@ConsigneeAddr",Consignee.ConsigneeAddr),
                               new SqlParameter("@ConsigneeTel",Consignee.ConsigneeTel),
                               new SqlParameter("@UsersID",Consignee.UsersID)
                               };
            return helper.ExecNonquery_Proc("AddConsignee", par);
        }
        /// <summary>
        /// 修改用户收货地址
        /// </summary>
        /// <param name="Consignee"></param>
        /// <returns></returns>
        public int Consignees_Edit(WineModel.Consignee Consignee)
        {
            SqlParameter[] par ={
                               new SqlParameter("@ConsigneeName",Consignee.ConsigneeName),
                               new SqlParameter("@AreaID",Consignee.AreaID),
                               new SqlParameter("@ConsigneeAddr",Consignee.ConsigneeAddr),
                               new SqlParameter("@ConsigneeTel",Consignee.ConsigneeTel),
                               new SqlParameter("@ConsigneeID",Consignee.ConsigneeID)
                               };
            return helper.ExecNonquery_Proc("UpdConsignee", par);
        }
        /// <summary>
        /// 显示地区列表
        /// </summary>
        /// <returns></returns>
        public List<WineModel.Area> AreasShow()
        {
            List<WineModel.Area> list = new List<WineModel.Area>();
            DataTable table = helper.ExecDataTable_Proc("Areas_Show");
            foreach (DataRow dr in table.Rows)
            {
                WineModel.Area Area = new WineModel.Area();
                Area.AreaID = Convert.ToInt32(dr["AreaID"]);
                Area.AreaName = Convert.ToString(dr["AreaName"]);
                Area.UpperStory = Convert.ToInt32(dr["UpperStory"]);
                list.Add(Area);
            }
            return list;
        }
        /// <summary>
        /// 显示地区列表
        /// </summary>
        /// <returns></returns>
        public List<WineModel.Area> AreasSelect(int Aid)
        {
            List<WineModel.Area> list = new List<WineModel.Area>();
            SqlParameter par=new SqlParameter ("@AreaID",Aid);
            DataTable table = helper.ExecDataTable_Proc("AreaSelect", par);
            foreach (DataRow dr in table.Rows)
            {
                WineModel.Area Area = new WineModel.Area();
                Area.UpperStory = Convert.ToInt32(dr["UpperStory"]);
                list.Add(Area);
            }
            return list;
        }
    }
}
